// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  console.log("云函数接收到的数据为：",event)
  console.log("本次openid为：",event.openid)
  try {
    const result = await cloud.openapi.subscribeMessage.send({
      touser: event.openid, //要推送给那个用户
      page: 'pages/index/index', //要跳转到那个小程序页面
      data: {//推送的内容
        name1: {
          value: event.lostName
        },
        thing6: {
          value: event.locateion
        },
        date5: {
          value: event.lostTime
        },
        thing11:{
          value:'归家救援团队'
        }
      },
      templateId: 'X-oHowZphCP0il9GUyhu25A0Ughv81bLHxi0nEKtVY0' //模板id
    })
    console.log("订阅消息发送成功：",result)
    return result
  } catch (err) {
    console.log("订阅消息发送失败：",err)
    return err
  }
}